package NumberGame;

import java.util.Random;
import java.util.Scanner;

public class NumberGame {

    public void menu() {
        System.out.println("------------猜数字游戏-------------");
        System.out.println("-------1.开始游戏  0.退出游戏-------");
    }

    public void game() {
        Random random = new Random();
        int rand = random.nextInt(11);
        boolean flg=true;
        int count=1;
        while(flg){
            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入你要猜的数字(0~10)：");
            int number = scanner.nextInt();
            if(number>rand){
                System.out.println("猜大了！");
                count++;
            }
            if(number<rand){
                System.out.println("猜小了！");
                count++;
            }
            if(number==rand){
                System.out.println("恭喜你猜对了！");
                flg=false;
            }
        }
        System.out.println("猜了"+count+"次，真棒！！！");
    }
}
